<%@ page import="com.afc.struts.test.person.PersonForm" %>
<%@ page import="com.afc.struts.test.person.PersonForm.DefaultPersonForm" %>
<%@ page import="com.afc.struts.test.model.Person" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="com.afc.struts.utils.DateUtils" %>

<%
  String error = (String)request.getAttribute("error");
  PersonForm form = (PersonForm)request.getAttribute("form");
  if (form == null)
  {
    form = new DefaultPersonForm();
  }
%>

<html>
<head>
<script type="text/javascript">
function submitForm(anActionUrl, aFormElement)
{
  aFormElement.action = anActionUrl;
  aFormElement.submit();
}
</script>
</head>

<body>
  <a href="welcome.jsp">Welcome</a>
  <form method="post">
    FirstName : <input type="text" attribute-type="java.lang.String" name="firstName" value='<%= form.getFirstName() != null ? form.getFirstName() : "" %>' /><br />
    LastName : <input type="text" attribute-type="java.lang.String" name="lastName" value='<%= form.getLastName() != null ? form.getLastName() : "" %>' /><br />
    Size : <input type="text" attribute-type="java.lang.Double" name="size" value='<%= form.getSize() != null ? form.getSize() : "" %>' /><br />
    Birthday : <input type="text" attribute-type="java.util.date" name="birthday" value='<%= form.getBirthday() != null ? DateUtils.format(form.getBirthday()) : "" %>' /><br />
    BestFriend : <select attribute-type="com.afc.struts.test.model.Person" name="bestFriend">
      <%
        Iterator iterator = form.getPossibleBestFriends().iterator();
        for (int i = 0; iterator.hasNext(); i++)
        {
          Person bestFriend = (Person)iterator.next();
      %>
          <option value=<%= i %> <%= (bestFriend != null && form.getBestFriend() != null && bestFriend.getId() == form.getBestFriend().getId()) || bestFriend == form.getBestFriend() ? "selected" : "" %>><%= bestFriend != null ? bestFriend : "" %></option>
      <%
        }
      %>
    </select><br />
    <input type="button" value="Add" onclick='submitForm("personAdd.ok.do", this.form)' />
    <a href="persons.jsp"><input type="button" value="Cancel" /></a>
    <label><%= error != null ? error : "" %></label>
  </form>

</body>

</html>